package com.ittony.util;

import java.sql.*;

public class JDBCUtil {
    private static String driverName = "com.mysql.jdbc.Driver";
    private static String url = "jdbc:mysql://localhost:3306/dormitory";
    private static String user = "root";
    private static String password = "Tq971221!";
    static{
        try {
            Class.forName(driverName);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    public static Connection getConnection(){
        Connection conn = null;
        try {
            conn = DriverManager.getConnection(url, user, password);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return conn;
    }
    public static void close(Connection conn, Statement stmt, ResultSet rs){
        try {
            if (conn != null){
                conn.close();
            }
            if (stmt != null){
                stmt.close();
            }
            if (rs != null){
                rs.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
